# @Timer:2022/3/28
# @作者:meng
# @文件名:json2.py
import  json

data = {'name':'杨','age':18,'a':True,'b':False,'c':None}

'''dumps:把python对象转为json字符串'''
#indent:缩进     ensure_ascii：编码格式，当有中文时，设置为False
json_data = json.dumps(data,indent=4,ensure_ascii=True)
# print(json_data,type(json_data))

'''loads:把json字符串转为python对象'''
data1 = json.loads(json_data)
# print(data1,type(data1))

'''dump:把python对象转为json字符串，并写入文件中'''
with open('json_data.txt','a',encoding='utf-8') as f:
    json.dump(data,f)

'''load:从json字符串文件中读取数据，并转为python对象'''
# with open('json_data.txt','r',encoding='utf-8') as f:
#     data2 = json.load(f)

# print(data2)